﻿using System;
using System.Collections.Generic;
using SmartHRMS.Presentation.Account;
using SmartHRMS.Model.Account;

namespace SmartHRMS.UI.Web.Modules.Administration.Account
{
    public partial class RoleList : System.Web.UI.UserControl, IRoleListView
    {
        private RoleListPresenter _Presenter;

        private static IList<Role> localRoleList = null;

        protected void Page_Init(object sender, EventArgs e)
        {
            _Presenter = new RoleListPresenter(this);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _Presenter.Display();
            }
        }

        #region IBaseView Members

        public void ErrorMessage(string Message)
        {
            if (String.IsNullOrEmpty(Message))
            {
                pnlError.Visible = false;
            }
            else
            {
                pnlError.Visible = true;
            }
            this.litErrorMessage.Text = Message + "<br/>";
        }

        public void InfoMessage(string Message)
        {
            if (String.IsNullOrEmpty(Message))
            {
                pnlInfo.Visible = false;
            }
            else
            {
                pnlInfo.Visible = true;
            }
            this.litInfoMessage.Text = Message + "<br/>";
        }

        public void WarringMessage(string Message)
        {
            if (String.IsNullOrEmpty(Message))
            {
                //    pnlWarr.Visible = false;
            }
            else
            {
                //   pnlWarr.Visible = true;
            }
            //  this.litWarrMessage.Text = Message + "<br/>";
        }

        public void ViewTitle(string title)
        {
            //throw new NotImplementedException();
        }

        #endregion

        #region IUserListView Members

        IList<Role> IRoleListView.Role
        {
            set
            {
                localRoleList = value;
                this.grdRoles.DataSource = localRoleList;
                this.grdRoles.DataBind();
            }
        }

        #endregion


        protected void btnNew_Click(object sender, EventArgs e)
        {
            Response.Redirect("RoleDetailPage.aspx?id=0");
        }

        protected void grdRoles_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            string deleteComand = e.CommandName.ToLower().ToString();
            if (deleteComand == "deleterole")
            {
                _Presenter.RemoveRoleBy(new Guid(e.CommandArgument.ToString()));
            }
        }
    }
}